package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TRobot;
import com.ruoyi.system.service.ITRobotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机器人Controller
 * 
 * @author wangdn
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/system/robot")
@Anonymous
@Api(tags = "机器人")
public class TRobotController extends BaseController
{
    @Autowired
    private ITRobotService tRobotService;

    /**
     * 查询机器人列表
     */
    @PreAuthorize("@ss.hasPermi('system:robot:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRobot tRobot)
    {
        startPage();
        List<TRobot> list = tRobotService.selectTRobotList(tRobot);
        return getDataTable(list);
    }

    /**
     * 导出机器人列表
     */
    @PreAuthorize("@ss.hasPermi('system:robot:export')")
    @Log(title = "机器人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRobot tRobot)
    {
        List<TRobot> list = tRobotService.selectTRobotList(tRobot);
        ExcelUtil<TRobot> util = new ExcelUtil<TRobot>(TRobot.class);
        util.exportExcel(response, list, "机器人数据");
    }

    /**
     * 获取机器人详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:robot:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tRobotService.selectTRobotById(id));
    }

    /**
     * 新增机器人
     */
//    @PreAuthorize("@ss.hasPermi('system:robot:add')")
//    @Log(title = "机器人", businessType = BusinessType.INSERT)
    @PostMapping()
    @ApiOperation(value = "新增机器人")
    public AjaxResult add(@RequestBody TRobot tRobot) throws Exception {
        return toAjax(tRobotService.insertTRobot(tRobot));
    }

    /**
     * 修改机器人
     */
    @PreAuthorize("@ss.hasPermi('system:robot:edit')")
    @Log(title = "机器人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRobot tRobot)
    {
        return toAjax(tRobotService.updateTRobot(tRobot));
    }

    /**
     * 删除机器人
     */
    @PreAuthorize("@ss.hasPermi('system:robot:remove')")
    @Log(title = "机器人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tRobotService.deleteTRobotByIds(ids));
    }
}
